(function() {
    angular.module('BlurAdmin.pages.UserlistM')
        .controller('systemCtrl', systemCtrl);

    function systemCtrl($scope, $openModal, $http, $myconfig, tongxin, $mydialog) {


        console.log(user.user);
        $scope.my_user = user.user;
        $scope.open = $openModal; //创建实例化对象
        function fn(val) { //关闭模态框方法
            $scope.myopen.opt_close = val;
        }

        function fn2(val) { //销毁实力方法
            $scope.myopen.dismiss = val;
        }

        $scope.myopen = function(id) { //打开模态框
            tongxin.setUserInfo(id);
            $scope.open.newOpen('app/pages/UserlistM/system/newSystem.html', 'lg', $scope, fn, 'static');
        }

        $scope.search_opt = {
            "limit": 10,
            "page": 1,
        };

        //分页
        // $scope.bigTotalItems = 50;
        $scope.pageChanged = function(val) {
            var Page_num = val //选中的页面数
            $scope.search_opt.page = val;
            Search_list();
        };
        $scope.Search = function() {
            $http.get($myconfig.api.users_users_admin_count).then(function(res) {
                $scope.bigTotalItems = res.data.data;
                Search_list();
            })

        }

        function Search_list() { //获取用户数据
            var opt = $scope.search_opt;
            $http.get($myconfig.api.users_users_admin_list, { params: opt }).then(function(res) {
                if (res.data.success) {
                    for (var i = 0; i < res.data.data.length; i++) { //添加条数属性
                        res.data.data[i].index = (($scope.search_opt.page - 1) * $scope.search_opt.limit) + i + 1;
                    }
                    $scope.list_data = res.data.data;
                }
                console.log($scope.list_data);
            })
        }
        $scope.Search();

        //确认删除

        var user_id = null;

        function my_callback(val) {
            if (val == true) {
                $http.post($myconfig.api.users_users_remove_admin, {
                    admin_id: notice_id
                }).then(function(res) {
                    console.log(res);
                    $scope.Search();
                })
            }
        };

        $scope.fn_delete = function(val) {
            notice_id = val;
            $mydialog.inquiry('确定要删除吗？', my_callback)
        };




    }
})();